package com.tencreat.account.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.account.CommonWithdrawConfig;
import com.tencreat.service.account.ICommonWithdrawConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 提现设置Controller
 *
 * @author tencreat
 * @date 2021-09-11
 */
@Api(tags="提现设置api")
@RestController
@RequestMapping("/system/withdrawConfig")
public class CommonWithdrawConfigController extends BaseController {
    @Autowired
    private ICommonWithdrawConfigService commonWithdrawConfigService;

    /**
     * 查询提现设置列表
     */
    @ApiOperation(value="查询提现设置列表")
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @PostMapping("/list")
    public HttpResult<IPage<CommonWithdrawConfig>> list(@RequestBody  CommonWithdrawConfig commonWithdrawConfig) {
        QueryWrapper<CommonWithdrawConfig> wrapper = Wrappers.query(commonWithdrawConfig);
        Page<CommonWithdrawConfig> page =  new Page<>(commonWithdrawConfig.getPageNum(), commonWithdrawConfig.getPageSize());
        return HttpResult.ok(commonWithdrawConfigService.page(page, wrapper));
    }

    /**
     * 导出提现设置列表
     */
    @ApiOperation(value="导出提现设置列表")
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "财务管理>提现设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(CommonWithdrawConfig commonWithdrawConfig) {
        List<CommonWithdrawConfig> list = commonWithdrawConfigService.selectCommonWithdrawConfigList(commonWithdrawConfig);
        ExcelUtil<CommonWithdrawConfig> util = new ExcelUtil<CommonWithdrawConfig>(CommonWithdrawConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 获取提现设置详细信息
     */
    @ApiOperation(value="获取提现设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<CommonWithdrawConfig> getInfo(@RequestBody ReqIdParam id) {
        return HttpResult.ok(commonWithdrawConfigService.selectCommonWithdrawConfigById(id));
    }

    /**
     * 新增提现设置
     */
    @ApiOperation(value="新增提现设置")
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "财务管理>提现设置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  CommonWithdrawConfig commonWithdrawConfig) {
        return to(commonWithdrawConfigService.insertCommonWithdrawConfig(commonWithdrawConfig));
    }

    /**
     * 修改提现设置
     */
    @ApiOperation(value="修改提现设置")
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "财务管理>提现设置", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  CommonWithdrawConfig commonWithdrawConfig) {
        return to(commonWithdrawConfigService.updateCommonWithdrawConfig(commonWithdrawConfig));
    }

    /**
     * 删除提现设置
     */
    @ApiOperation(value="删除提现设置")
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "财务管理>提现设置", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody ReqIdsParam ids) {
        return to(commonWithdrawConfigService.deleteCommonWithdrawConfigByIds(ids));
    }




    /**
     * 导出统计表格
     */
    @ApiOperation(value="导出统计表格")
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "首页>导出统计表格", businessType = BusinessType.EXPORT)
    @PostMapping("/statisticsExport")
    public AjaxResult statisticsExport() {
        ArrayList<Object> list = new ArrayList<>();
        ExcelUtil<Object> util = new ExcelUtil<Object>(Object.class);
        return util.exportExcel(list, "statisticsExport");
    }
}
